Namespace effority.UserDirectory.Scheduler

    Public Class LoadGlobalCache
        Inherits DotNetNuke.Services.Scheduling.SchedulerClient

        Public Sub New(ByVal objScheduleHistoryItem As DotNetNuke.Services.Scheduling.ScheduleHistoryItem)

            MyBase.new()

            Me.ScheduleHistoryItem = objScheduleHistoryItem

        End Sub

        Public Overrides Sub DoWork()

            Try

                'Dim ds As UD_DataSet = effority.UserDirectory.DataSet.GetTypedDS()

                'Dim cache As DotNetNuke.Services.Cache.CachingProvider = DotNetNuke.Services.Cache.CachingProvider.Instance

                'cache.Insert(Consts.GLOBAL_CACHE, ds, False)

                'ScheduleHistoryItem.AddLogNote("Load Global Cache Completed<br /><br />")

                'ScheduleHistoryItem.AddLogNote(String.Format("Roles = {0}<br /><br />", ds.Roles.Rows.Count))
                'ScheduleHistoryItem.AddLogNote(String.Format("Users = {0}<br /><br />", ds.Users.Rows.Count))
                'ScheduleHistoryItem.AddLogNote(String.Format("Profile Properties = {0}<br /><br />", ds.ProfilePropertyDefinition.Rows.Count))

                Dim cont As New DotNetNuke.Entities.Modules.DesktopModuleController

                Dim info As DotNetNuke.Entities.Modules.DesktopModuleInfo = cont.GetDesktopModuleByModuleName("effority.UserDirectory")

                Dim moduleCont As New DotNetNuke.Entities.Modules.ModuleController

                Dim allModules As ArrayList = moduleCont.GetAllModules()

                Dim modules As New ArrayList

                For Each moduleInfo As DotNetNuke.Entities.Modules.ModuleInfo In allModules

                    If moduleInfo.DesktopModuleID = info.DesktopModuleID Then
                        modules.Add(moduleInfo)
                    End If
                Next

                For Each moduleInfo As DotNetNuke.Entities.Modules.ModuleInfo In modules

                    Dim fake As New effority.UserDirectory.Scheduler.FakeView

                    fake.ModuleId = moduleInfo.ModuleID
                    fake.TabModuleId = moduleInfo.TabModuleID
                    fake.PortalId = moduleInfo.PortalID

                    fake.makeCache()

                    ScheduleHistoryItem.AddLogNote(moduleInfo.ModuleTitle & "<BR>")

            Next


            ScheduleHistoryItem.Succeeded = True

            Catch ex As Exception

                ScheduleHistoryItem.Succeeded = False

                ScheduleHistoryItem.AddLogNote("LoadGlobalCache Failed <br /><br /> EXCEPTION:<br /><br /> " & ex.Message)

                Errored(ex)

                DotNetNuke.Services.Exceptions.LogException(ex)

            End Try

        End Sub

    End Class

End Namespace
